package com.atguigu.spzx.user.controller;

import com.atguigu.spzx.common.result.Result;
import com.atguigu.spzx.common.result.ResultCodeEnum;
import com.atguigu.spzx.user.service.UserInfoService;
import com.atguigu.spzx.user.vo.UserInfoRespVo;
import com.atguigu.spzx.user.vo.UserLoginReqVo;
import com.atguigu.spzx.user.vo.UserRegisterReqVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * UserInfoController
 * </p>
 *
 * @author flyduck
 * @since 2023/11/5
 */
@Api(tags = "用户管理接口")
@RestController
@RequestMapping("/api/user/userInfo")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("用户注册")
    @PostMapping("/register")
    public Result register(@RequestBody UserRegisterReqVo vo){
        userInfoService.register(vo);
        return Result.ok();
    }

    @ApiOperation("会员登录")
    @PostMapping("/login")
    public Result login(@RequestBody UserLoginReqVo vo){
        String token = userInfoService.login(vo);
        return Result.ok(token);
    }

    @ApiOperation("获取当前登录用户信息")
    @GetMapping("auth/getCurrentUserInfo")
    public Result<UserInfoRespVo> getCurrentUserInfo(@RequestHeader("token") String token) {
        UserInfoRespVo vo = userInfoService.getCurrentUserInfo(token) ;
        return Result.ok(vo);
    }

}
